/* Copyright (C) Scott Bilas, 2000. 
* All rights reserved worldwide.
*
* This software is provided "as is" without express or implied
* warranties. You may freely copy and compile this source into
* applications you distribute provided that the copyright text
* below is included in the resulting source code, for example:
* "Portions Copyright (C) Scott Bilas, 2000"
*/
#ifndef ISINGLETON_H_
#define ISINGLETON_H_

#include <cassert>


#ifdef _MSC_VER
#   pragma warning (disable : 4311)
#   pragma warning (disable : 4312)
#endif

template <typename T>
class ISingleton
{
public:
	static T* m_pInstance;

public:
	ISingleton()
	{
		assert(!m_pInstance);

#if defined( _MSC_VER ) && _MSC_VER < 1200	 
		int offset = (int)(T*)1 - (int)(ISingleton <T>*)(T*)1;
		m_pInstance = (T*)((int)this + offset);
#else
		m_pInstance = static_cast<T*>(this);
#endif

	}
	~ISingleton()
	{  
		assert(m_pInstance);
		m_pInstance = 0;  
	}

	static T& GetInstance()
	{  
		assert(m_pInstance );  
		return (*m_pInstance);  
	}
	static T* GetInstancePtr()
	{  
		return (m_pInstance);  
	}
};

//template < typename T > T* ISingleton < T >::m_pInstance = 0;

#endif /*ISINGLETON_H_*/
